package com.cloudkinto.controller.order;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.order.OrderAmazonVdfItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 亚马逊供应商api订单商品信息子表 前端控制器
 * </p>
 *
 * @author ding
 * @since 2024-06-19
 */
@Deprecated
@RestController
@Api(tags = "亚马逊供应商api订单商品信息子表模块")
@RequestMapping("/api/OrderAmazonVendorItem")
public class OrderAmazonVdfItemController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(OrderAmazonVdfItemController.class);

    @Autowired
    private OrderAmazonVdfItemService service;

    @GetMapping("/addInit")
    @ApiOperation(value = "亚马逊供应商api订单商品信息子表新增初始化", notes = "亚马逊供应商api订单商品信息子表新增初始化")
    public SingleResult addInit() {
        return service.addInit();
    }

    @PostMapping("")
    @ApiOperation(value = "亚马逊供应商api订单商品信息子表新增", notes = "亚马逊供应商api订单商品信息子表新增")
    public SingleResult add(@RequestBody @Validated Object req) {
        Long userId = getCurrentUserId();
        Long companyId = getCompanyId();
        return SingleResult.success("新增成功", service.add(req, userId));
    }

    @GetMapping("/updateInit/{id}")
    @ApiOperation(value = "亚马逊供应商api订单商品信息子表编辑初始化", notes = "亚马逊供应商api订单商品信息子表编辑初始化")
    public SingleResult updateInit(@PathVariable("id") Long id) {
        return service.updateInit(id);
    }

    @PutMapping("")
    @ApiOperation(value = "亚马逊供应商api订单商品信息子表修改", notes = "亚马逊供应商api订单商品信息子表修改")
    public SingleResult update(@RequestBody @Validated Object req) {
        Long userId = getCurrentUserId();
        return SingleResult.success("修改成功", service.update(req, userId));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "亚马逊供应商api订单商品信息子表根据id删除", notes = "亚马逊供应商api订单商品信息子表根据id删除")
    public SingleResult delete(@PathVariable("id") Long id) {
        Long userId = getCurrentUserId();
        return SingleResult.success("删除成功", service.delete(id, userId));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "亚马逊供应商api订单商品信息子表根据id查看详情", notes = "亚马逊供应商api订单商品信息子表根据id查看详情")
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", service.detail(id));
    }

    @GetMapping("/pageInit")
    @ApiOperation(value = "亚马逊供应商api订单商品信息子表查询初始化", notes = "亚马逊供应商api订单商品信息子表查询初始化")
    public SingleResult pageInit() {
        return service.pageInit();
    }

    @GetMapping("/list")
    @ApiOperation(value = "亚马逊供应商api订单商品信息子表查询", notes = "亚马逊供应商api订单商品信息子表查询")
    public SingleResult list(HttpServletRequest request) {
        Long companyId = getCompanyId();

        Map<String, String> map = new HashMap<>();
        String keyword = request.getParameter("keyword");
        map.put("keyword", keyword);
        return SingleResult.success("查询成功", service.getList(map));
    }

    @GetMapping("/listPage")
    @ApiOperation(value = "亚马逊供应商api订单商品信息子表查询（分页）", notes = "亚马逊供应商api订单商品信息子表查询（分页）")
    public PageResult listPage(HttpServletRequest request) {
        Long companyId = getCompanyId();

        Map<String, String> map = new HashMap<>();
        String keyword = request.getParameter("keyword");
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        map.put("keyword", keyword);
        map.put("current", current);
        map.put("pageSize", size);
        return service.getListPage(map);
    }

}

